from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import text
from sqlalchemy import create_engine
from mysqlconn import getSession
dbHost = 'mysql+pymysql://root:123456@127.0.0.1:3306/hzrag'
engine = create_engine(
    dbHost,
    echo=True,  # 是否打印SQL
    pool_size=10,  # 连接池的大小，指定同时在连接池中保持的数据库连接数，默认:5
    max_overflow=20,  # 超出连接池大小的连接数，超过这个数量的连接将被丢弃,默认: 5
)

Base = declarative_base()
Session = sessionmaker(bind=engine)
session = Session()

result = session.execute(text("SELECT * FROM t_file WHERE name LIKE :username"), {"username": "%example%"})
 


final=[]    
for row in result:
    print(row) 
    final.append(row._asdict())
print(final)


def queryRows():
    """ 查询示例 """
    with getSession() as session:
        result = session.execute(text("SELECT * FROM t_file WHERE name LIKE :username"), {"username": "%example%"})
        final=[]    
        for row in result:
            print(row) 
            final.append(row._asdict())
        
        return final
print("....fin....") 
fin=queryRows()
print(fin) 